package a_arguments;
/*
    可变长参数的使用
 */
public class Demo {
    public static void main(String[] args) {

        sum(2,3);
        //sum(new int[]{1,2,3,4,5});
        int sum = sum(2, 3, 4, 5, 6, 7, 8, 9, 10);
        int sum1 = sum(2, 3, 4);
        System.out.println(sum1);
        sum(6,9,10,100);

    }

    //需求:假设传入n和m个值,将两个值相加,并返回
    public static int sum(int n, int m){
        return n + m;
    }


    /*public static int sum(int[] arr){

        return arr[0];
    }*/

    //优化数组的写法
    public static int sum(int... arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    public static int sum(int a,String str,int... arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }


}
